﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DormMS.IService;
using DormMS.Model.SearchModels;
using DormMS.Model.ViewModels;

namespace DormMS.Controllers
{
    public class ProductExchangeController : BaseController
    {
        private IExchangeService exchangeservice;
        public ProductExchangeController(IUserInfoService s, IExchangeService _exchangeservice) : base(s)
        {
            exchangeservice = _exchangeservice;
        }

        // GET: ProductExchange
        [AuthorizeFilter(MenuRole = "71")]
        [HttpGet]
        public ActionResult ExchangeManage()
        {
            return View();
        }

        [AuthorizeFilter(MenuRole = "71")]
        [HttpPost]
        public ActionResult ExchangeManage(ExchangeSearchModel search)
        {
            int total = 0;
            var list = exchangeservice.ExchangeManage(search, out total);
            return Json(new { Total = total, Results = list });
        }


        [AuthorizeFilter(MenuRole = "71")]
        [HttpPost]
        public ActionResult DelExchange(int Id)
        {
            return Json(exchangeservice.DelExchange(Id, CurrentLoginUser.Id));
        }

        [AuthorizeFilter(MenuRole = "71")]
        [HttpPost]
        public ActionResult ChangeDisplay(int Id)
        {
            return Json(exchangeservice.ChangeDisplay(Id, CurrentLoginUser.Id));
        }

        [AuthorizeFilter(MenuRole = "71")]
        [HttpGet]
        public ActionResult ExchangeEdit()
        {
            return View();
        }

        [AuthorizeFilter(MenuRole = "71")]
        [HttpPost]
        public ActionResult ExchangeEdit(int Id)
        {
            return Json(exchangeservice.ExchangeEdit(Id));
        }

        [AuthorizeFilter(MenuRole = "71")]
        [HttpPost]
        public ActionResult ExchangeEditSubmit(ProductExchangeResponse ExchangeModel)
        {
            return Json(exchangeservice.ExchangeEditSubmit(ExchangeModel,CurrentLoginUser.Id));
        }

        [AuthorizeFilter(MenuRole = "71")]
        [HttpPost]
        public ActionResult GetMemberLevels()
        {
            return Json(exchangeservice.GetMemberLevels());
        }

    }
}